package cn.itcast.com.Thread;

public class yield {
    public static void main(String[] args) {
        yielthread yielthread1 = new yielthread();
        yielthread yielthread2 = new yielthread();
        yielthread1.start();
        yielthread2.start();
    }
}
//暂停目前正在执行的线程对象，并执行其他线程
class yielthread extends Thread {
    @Override
    public void run(){
        for (int i = 0; i < 100; i++) {
            System.out.println(getName()+" "+ i);
            //调用礼让方法
            Thread.yield();
        }
    }
}